<!--
 * @Author: 乌日汗 3337511892@qq.com
 * @Date: 2025-09-11 08:39:01
 * @LastEditors: 乌日汗 3337511892@qq.com
 * @LastEditTime: 2025-09-17 15:48:22
 * @FilePath: \大三上 前端\city\src\pages\components\Left1 copy.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div>
        <Title :title="title"></Title>
        <!-- 1.提供图表容器  ref模板引用 类似于id  -->
        <div ref="bottom4" style="height: 150px;margin-top: 10px;"></div>

        
    </div>
</template>
<script>
import { CirclePacking,Sunburst } from '@antv/g2plot';
import { Area } from '@antv/g2plot';

// 引入get请求 @表示src别名 
import { get } from '@/utils/request';
// 引入momentjs
import moment from 'moment';
// import axios from 'axios';
import { mapState } from 'vuex';




export default {
    data() {
        return {
            title: '监测内容',
            params: {

                page: 1,
                pageSize: 200
            },
            // 存放温度数据
            monitorData: [],
            // 创建一个图表实例 
            circlePacking: null
        }
    },
    computed: {
        ...mapState(['ed'])
    },
    // 侦听器 侦听数据 
    watch: {
        ed: {
            handler(n, o) {
                // 根据设备信息重新查询数据 重新渲染图表
                // console.log(n,'11111111111111'); 
                this.params.engineer_id = n.engineer_id;
                this.params.device_id = n.device_id;
                this.getServiceData();
                // 根据最新获取的数据重新渲染图表 
                this.line.changeData(this.serviceData);
            },
            // 深度监听 
            deep: true
        }
    },
    methods: {

        // 封装加载折线图图表函数 
        loadLine() {
            const plot = new Sunburst(this.$refs.bottom4, {
                data: {
                    "name": "温度湿度",
                    "children": [
                        {
                            "name": "非洲",
                            "value": 4,
                            "children": [
                                {
                                    "continent": "非洲",
                                    "country": "埃塞俄比亚",
                                    "symbol": "🇪🇹",
                                    "area": "耶加雪菲",
                                    "name": "埃塞俄比亚",
                                    "value": 1
                                },
                                {
                                    "continent": "非洲",
                                    "country": "肯尼亚",
                                    "symbol": "🇰🇪",
                                    "coffee": "阿拉比加卡豆",
                                    "name": "肯尼亚",
                                    "value": 1
                                },
                                {
                                    "continent": "非洲",
                                    "country": "坦桑尼亚",
                                    "symbol": "🇹🇿",
                                    "coffee": "乞力马扎罗咖啡",
                                    "name": "坦桑尼亚",
                                    "value": 1
                                },
                                {
                                    "continent": "非洲",
                                    "country": "乌干达",
                                    "symbol": "🇺🇬",
                                    "name": "乌干达",
                                    "value": 1
                                }
                            ]
                        },
                        {
                            "name": "中南美洲",
                            "value": 6,
                            "children": [
                                {
                                    "continent": "中南美洲",
                                    "country": "巴西",
                                    "symbol": "🇧🇷",
                                    "name": "巴西",
                                    "value": 1
                                },
                                {
                                    "continent": "中南美洲",
                                    "country": "哥伦比亚",
                                    "symbol": "🇨🇴",
                                    "name": "哥伦比亚",
                                    "value": 1
                                },
                                {
                                    "continent": "中南美洲",
                                    "country": "牙买加",
                                    "symbol": "🇯🇲",
                                    "name": "牙买加",
                                    "value": 1
                                },
                                {
                                    "continent": "中南美洲",
                                    "country": "巴拿马",
                                    "symbol": "🇵🇦",
                                    "name": "巴拿马",
                                    "value": 1
                                },
                                {
                                    "continent": "中南美洲",
                                    "country": "危地马拉",
                                    "symbol": "🇬🇹",
                                    "name": "危地马拉",
                                    "value": 1
                                },
                                {
                                    "continent": "中南美洲",
                                    "country": "哥斯达黎加",
                                    "symbol": "🇨🇷",
                                    "name": "哥斯达黎加",
                                    "value": 1
                                }
                            ]
                        },
                        {
                            "name": "亚洲",
                            "value": 5,
                            "children": [
                                {
                                    "continent": "亚洲",
                                    "country": "印度尼西亚",
                                    "symbol": "🇮🇩",
                                    "area": "苏门答腊",
                                    "coffee": "曼特宁咖啡",
                                    "name": "印度尼西亚",
                                    "value": 1
                                },
                                {
                                    "continent": "亚洲",
                                    "country": "印度",
                                    "symbol": "🇮🇳",
                                    "name": "印度",
                                    "value": 1
                                },
                                {
                                    "continent": "亚洲",
                                    "country": "越南",
                                    "symbol": "🇻🇳",
                                    "name": "越南",
                                    "value": 1
                                },
                                {
                                    "continent": "亚洲",
                                    "country": "也门",
                                    "symbol": "🇾🇪",
                                    "name": "也门",
                                    "value": 1
                                },
                                {
                                    "continent": "亚洲",
                                    "country": "中国",
                                    "symbol": "🇨🇳",
                                    "name": "中国",
                                    "value": 1
                                }
                            ]
                        }
                    ]
                },
                innerRadius: 0.3,
                interactions: [{ type: 'element-active' }],
            });
            plot.render();
        },
        // 封装方法获取后端接口的实时数据 
        async getServiceData() {
            let res = await get('/dashboard/pageQueryTodayData', this.params);
            // console.log(res, "获取响应");
            let service = [];
            // 将后端获取的数据设置给tempData 
            res.data.list.forEach((item, index, arr) => {
                // 由于刻度混乱 将第一条数据值设置为15.4 
                arr[0].humidity = 15.4;
                // item表示数组每一项 
                item.insert_time = moment(item.insert_time).format("HH:mm");
                // 由于查询数据密度密集 需要将数据处理 每隔10条数据取一条数据 
                if (index % 10 == 0) {
                    service.push(arr[index])
                }
            });
            this.serviceData = service;
        }
    },
    // 最早获取dom元素的生命周期  图表渲染dom元素
    async mounted() {
        await this.getServiceData();
        this.loadLine();
    }




}
</script>






<style lang="less" scoped></style>